<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="待单打印">
    <style media="print">
        @page {
            margin: 0mm; /* this affects the margin in the printer settings */
            size: landscape;
        }
    </style>

    <style>
        table{border-collapse: collapse;width: 100%}
        table td, table th{border: 1px solid #000000;}
        table td{padding:4px 0 4px 4px;}
        table td, table th{border: 1px solid #000000;}
        span,div,td,th{font-size:14px;}
    </style>

    <script>
        function printAllPage(data){
            let $printDiv = $("#printDiv");
            $printDiv.empty();

            genPrintDiv($printDiv, data.id, "待入库单", data.no);
            let beforeList = [];
            let linkOrder = genLinOrder(data);

            if (linkOrder.linkUnit != "") {
                beforeList.push({label:"往来单位", content:linkOrder.linkUnit.name});
            } else {
                beforeList.push({label:"往来单位", content:""});
            }

            beforeList.push({newLine:true, width:0,label:"入库仓库", content:data.houseVo.store.name + ">" + data.houseVo.name});

            beforeList.push({label:"关联单经办人", content:linkOrder.user.name});
            beforeList.push({width:180, label: "关联单日期", content: GMTToDate(linkOrder.date)});
            beforeList.push({width:0, label: "关联单号", content: (linkOrder.no)});
            genPrintLine($('#'+data.id+' .before'), beforeList);

            let endList = [];
            endList.push({width:0, newLine: true,label:"备注", content:data.remark==null?"":data.remark});
            genPrintLine($('#'+data.id+' .end'), endList);

            let list=[];
            let index = 1;
            $.each(data.houseWaitInGoodsVoList, function (i,d) {
                let data={};
                let vo = d.goodsVo;
                data.index = index++;
                data.no = vo.no;
                data.name = vo.name;
                data.norms = genGoodsNorm(vo.norms);
                data.number = vo.number;
                data.waitInNumber = vo.waitInNumber;
                data.hasInNumber = vo.hasInNumber;
                data.unit = genUnitName(vo.goodsUnitVoList, vo.unitId);
                data.remark = vo.remark==null ? "" :  vo.remark;
                list.push(data);
            });

            $.each(data.houseWaitInPacketVoList, function (i,d) {
                let data={};
                let vo = d;
                data.index = index++;
                data.no = vo.packetNo;
                data.name = vo.packetName;
                data.norms = "";
                data.number = vo.number;
                data.waitInNumber = vo.waitInNumber;
                data.hasInNumber = vo.hasInNumber;
                data.unit = "";
                data.remark = vo.remark == null ? "" : vo.remark;
                list.push(data);
            });

            genPrintTable($('#'+data.id+' .table'), ['序号','商品编号','商品名称','规格','数量','未入库数量','已入库数量','单位','备注'],list);

            setTimeout(function () {
                window.print();
            },100);
        }

        function printWaitIn(data){
            let $printDiv = $("#printDiv");
            $printDiv.empty();

            genPrintDiv($printDiv, data.id, "待入库单", data.no);
            let beforeList = [];
            let linkOrder = genLinOrder(data);

            if (linkOrder.linkUnit != "") {
                beforeList.push({label:"往来单位", content:linkOrder.linkUnit.name});
            } else {
                beforeList.push({label:"往来单位", content:""});
            }

            beforeList.push({newLine:true, width:0,label:"入库仓库", content:data.houseVo.store.name + ">" + data.houseVo.name});

            beforeList.push({label:"关联单经办人", content:linkOrder.user.name});
            beforeList.push({width:180, label: "关联单日期", content: GMTToDate(linkOrder.date)});
            beforeList.push({width:0, label: "关联单号", content: (linkOrder.no)});
            genPrintLine($('#'+data.id+' .before'), beforeList);

            let endList = [];
            endList.push({width:0, newLine: true,label:"备注", content:data.remark==null?"":data.remark});
            genPrintLine($('#'+data.id+' .end'), endList);

            let list=[];
            let index = 1;
            $.each(data.houseWaitInGoodsVoList, function (i,d) {
                if (d.waitInNumber > 0) {
                    let data={};
                    let vo = d.goodsVo;
                    data.index = index++;
                    data.no = vo.no;
                    data.name = vo.name;
                    data.norms = genGoodsNorm(vo.norms);
                    data.number = vo.waitInNumber;
                    data.unit = genUnitName(vo.goodsUnitVoList, vo.unitId);
                    data.remark = vo.remark==null ? "" :  vo.remark;
                    list.push(data);
                }
            });
            $.each(data.houseWaitInPacketVoList, function (i,d) {
                let data={};
                let vo = d;
                if (d.waitInNumber > 0) {
                    data.index = index++;
                    data.no = vo.packetNo;
                    data.name = vo.packetName;
                    data.norms = "";
                    data.number = vo.waitInNumber;
                    data.unit = "";
                    data.remark = vo.remark == null ? "" : vo.remark;
                    list.push(data);
                }
            });


            genPrintTable($('#'+data.id+' .table'), ['序号','商品编号','商品名称','规格','数量','单位','备注'],list);

            setTimeout(function () {
                window.print();
            },100);
        }

        function printHasIn(data){
            let $printDiv = $("#printDiv");
            $printDiv.empty();

            genPrintDiv($printDiv, data.id, "待入库单", data.no);
            let beforeList = [];
            let linkOrder = genLinOrder(data);

            if (linkOrder.linkUnit != "") {
                beforeList.push({label:"往来单位", content:linkOrder.linkUnit.name});
            } else {
                beforeList.push({label:"往来单位", content:""});
            }

            beforeList.push({newLine:true, width:0,label:"入库仓库", content:data.houseVo.store.name + ">" + data.houseVo.name});

            beforeList.push({label:"关联单经办人", content:linkOrder.user.name});
            beforeList.push({width:180, label: "关联单日期", content: GMTToDate(linkOrder.date)});
            beforeList.push({width:0, label: "关联单号", content: (linkOrder.no)});
            genPrintLine($('#'+data.id+' .before'), beforeList);

            let endList = [];
            endList.push({width:0, newLine: true,label:"备注", content:data.remark==null?"":data.remark});
            genPrintLine($('#'+data.id+' .end'), endList);

            let list=[];
            let index=1;
            $.each(data.houseWaitInGoodsVoList, function (i,d) {
                if (d.hasInNumber > 0) {
                    let data={};
                    let vo = d.goodsId==null? d.packetVo:d.goodsVo;
                    data.index = index++;
                    data.no = vo.no;
                    data.name = vo.name;
                    data.norms = d.goodsId==null?'':genGoodsNorm(vo.norms);
                    data.number = vo.hasInNumber;
                    data.unit = d.goodsId==null?'':genUnitName(vo.goodsUnitVoList, vo.unitId);
                    data.remark = vo.remark==null ? "" :  vo.remark;
                    list.push(data);
                }
            });

            $.each(data.houseWaitInPacketVoList, function (i,d) {
                let data={};
                let vo = d;
                if (d.hasInNumber > 0) {
                    data.index = index++;
                    data.no = vo.packetNo;
                    data.name = vo.packetName;
                    data.norms = "";
                    data.number = vo.hasInNumber;
                    data.unit = "";
                    data.remark = vo.remark == null ? "" : vo.remark;
                    list.push(data);
                }
            });

            genPrintTable($('#'+data.id+' .table'), ['序号','商品编号','商品名称','规格','数量','单位','备注'],list);

            setTimeout(function () {
                window.print();
            },100);
        }


        //获取关联单结构体
        function genLinOrder(d) {
            let vo = {};

            if (d.type ==1) {
                vo = d.inGoodsVo;
                vo.linkUnit = d.inGoodsVo.provider;
                return vo;
            }
            if (d.type ==2) {
                vo = d.refundVo;
                vo.linkUnit = d.refundVo.custom;
                return vo;
            }

            if (d.type ==3) {
                vo = d.goodsTransferVo;
                vo.linkUnit = "";
                return vo;
            }
            if (d.type ==4) {
                vo = d.borrowInVo;
                vo.linkUnit = d.borrowInVo.provider;
                return vo;
            }
            if (d.type ==5) {
                vo = d.borrowOutVo;
                vo.linkUnit = d.borrowOutVo.custom;
                return vo;
            }
        }

        function genTypeName(type) {
            if (type ==1) {
                return ("进货");
            }
            if (type ==2) {
                return ("销售退货");
            }
            if (type ==3) {
                return ("调拨");
            }
            if (type ==4) {
                return ("借入");
            }
            if (type ==5) {
                return ("借出归还");
            }
        }
    </script>

</html:header>
<body>
<div id="printDiv">
</div>
</body>
</html>